<?php

class Strategy_manage  extends AdminManage
{
	private $_pagesize=10;//分页个数
	/**
	 * 初始化
	 */
	public function _init()
	{

	}

	/**
	 * 默认动作
	 */
	protected function _default()
	{

		#审核类型
		$type= $this->getParam('type');
		switch($type) {
			case 'pass':
				$nodatainfo =  '没有相匹配的战略合作信息';
				break;
			case 'no_pass':
				$nodatainfo = '没有相匹配的战略合作信息';
				break;
			default:
				$nodatainfo = '没有找到相匹配的战略合作信息';
		}

		#获取参数
		$key = $this->getParam('kw');
//		if($key != null){
//			$key = Encode::decodeURI($key);
//		}

		//时间
		$start=$this->getParam('start');
		$end=$this->getParam('end');

		#组合查询语句
		$strWhere = '';

		if(empty($type)){
			$strCheckState = '  status in(0,1)';
		}else{
			#审核状态
			switch($type) {
				case 'pass':
					$checkState = 1;
					break;
				case 'no_pass':
					$checkState = 0;
					break;

			}

			$strCheckState = '  status = '.intval($checkState);

		}

		if(!empty($key)){
			$strWhereKey = ' and corpName like \'%'.$key.'%\''  ;
			//				$strWhereKey= "and title like '%$key%'";
		}

		if($key==0&&is_numeric($key)){
			$strWhereKey = ' and corpName like  \'%0%\' ';
		}

		if($start && $end){
			$start1=$start/1000;
			$end1=$end/1000+86400;
			$strWhereStart=' and firstTime between  '.$start1. ' and ' .$end1  ;
		}

//		$strWhereType=' and  type=2';


		#查询条件
		$strWhere = $strWhere.$strCheckState.$strWhereKey.$strWhereStart;

		#获取数据总数
		$total = DB::getRows('sc_corpinfo',$strWhere);


		/**分页操作 start**/
		$p = 1; //当前页码
		if (isset($_GET['p']) && is_numeric($_GET['p'])) {
			$p =intval($_GET['p']);
			if ($p<=1) {
				$p = 1;
			}
		}

		$totalPage = ceil($total/$this->_pagesize);//计算总页数
		$begin = ($p-1)*$this->_pagesize;//计算开始游标
		$limit = "$begin,$this->_pagesize";//计算分页



		$pageObj = new Dpage($total, $this->_pagesize, $p);
		$pageCss = $pageObj->pageCss("1");
		$pageform = $pageObj->outputPages(1,"<li>","</li>");

		/**分页操作 end**/


		#获取数据信息
		$list = new publicGetDataModel();
		$listData = $list->getData($where = $strWhere,$limit = $limit,$fields = 'id,userId,corpName,countryCode,address,linkman,mobile,tel,email,status,firstTime',$order = 'firstTime',$table='sc_corpinfo');

		if(empty($listData)) {
			if (isset($key)) {
				$nodatainfo = '没有找到相匹配的战略合作信息';
			}
		}


		if($listData){
			$i=0;
			foreach($listData  as $k=>$v){
				$i++;
				$listData[$k]['autoid']=$i;


				//地区处理
				if(!empty($listData[$k]['COUNTRYCODE'])){
					#获取地区信息
					#省份信息
					include_once(SYSTEM_PATH.'libs/data/province.lib.php');
					$strProvince = '';
					if( $listData[$k]['COUNTRYCODE']){
						$area_len = mb_strlen( $listData[$k]['COUNTRYCODE']);
						if($area_len==6){
							$strProvince = $Province2[ $listData[$k]['COUNTRYCODE']];
						}elseif ($area_len==9){
							$strProvince = $Province2[substr( $listData[$k]['COUNTRYCODE'],0,6)].$City[substr( $listData[$k]['COUNTRYCODE'],0,6)][ $listData[$k]['COUNTRYCODE']];
						}elseif ($area_len==12){
							$strProvince = $Province2[substr( $listData[$k]['COUNTRYCODE'],0,6)].$City[substr( $listData[$k]['COUNTRYCODE'],0,6)][substr( $listData[$k]['COUNTRYCODE'],0,9)].$County[substr( $listData[$k]['COUNTRYCODE'],0,9)][ $listData[$k]['COUNTRYCODE']];
						}
						$listData[$k]['AREAINFO'] = $strProvince;
//					print_r($strProvince);
					}



				}



			}
		}

//		DB::echoExeSql();

		$p=$this->getParam('p');
		if($p){
			$p=$p;
		}else{
			$p=1;
		}

		#模板赋值
		$now=time();
		$this->assign('now',$now);
		$this->assign('classify_list',$listData);
//		print_r($listData);
		$this->assign('pageCss',$pageCss);//分页样式
		$this->assign('pageform',$pageform);//分页标签
		$this->assign('type',$type);
		$this->assign('kw',$key);
		$this->assign('p',$p);
		$this->assign('start',$start/1000);
		$this->assign('end',$end/1000);
		$this->assign('nodatainfo',$nodatainfo);




		$this->assign('menu_navbar','合作管理  -- <a href="'.$_GET['action'].'.html">战略合作列表</a>');
		$this->tpl_full_path('/admins/strategy_manage/index');
	}
	
	
	
	/**
	 * 项目详情预览
	 */
	protected function _view()
	{
	    #登录状态可以看到本身所有状态的信息
		$intLoadId = $this->session()->getSession('uid');
		$p=$this->getParam('p');
		#保存修改操作
		if ($_SERVER["REQUEST_METHOD"] == "POST"){ 
		    $id = $this->getParam('id');
			$status = $this->getParam('status');
			if($id){
				$updateData = array();
				$updateData['status'] = $status?$status:0;
				$updateData['systemId'] = $intLoadId;
				$updateStatus = DB::update('sc_corpinfo','id = '.$id,$updateData);
				if($updateStatus){
					$message="保存成功！";
					$url='http://system.gzcanr.com/admins/strategy_manage-p-'.$p.'.html';
					$this->alertGoto($message,$url);
				}else{
					$this->alertBack("保存失败,请重试！");
				}
			}
			$this->alertBack("保存成功");
		}
		 
	
		#获取到参数
		$intId = $this->getParam('id');
		if(empty($intId) || !is_numeric($intId)){
			$this->goTo404();
		}

		$where='';
		$where.='id = '.$intId;
		$strWhere=$where;
		$list = new publicGetDataModel();
		$strategyData = $list->getData($where = $strWhere,$limit = 1,$fields = 'id,userId,corpName,countryCode,address,bLicense,principal,principal_mobile,linkman,mobile,tel,email,status,systemId,operateTime,firstTime ',$order = 'id',$table='sc_corpinfo');
		if($strategyData){
			#营业执照
			$strategyData[0]['BLICENSE'] = '/'.ltrim($strategyData[0]['BLICENSE'],'/');
			$strategyData = $strategyData[0];
			

			//地区处理
			if(!empty($strategyData['COUNTRYCODE'])){
				#获取地区信息
				#省份信息
				include_once(SYSTEM_PATH.'libs/data/province.lib.php');
				$strProvince = '';
				if( $strategyData['COUNTRYCODE']){
					$area_len = mb_strlen( $strategyData['COUNTRYCODE']);
					if($area_len==6){
						$strProvince = $Province2[ $projectData['COUNTRYCODE']];
					}elseif ($area_len==9){
						$strProvince = $Province2[substr( $strategyData['COUNTRYCODE'],0,6)].$City[substr( $strategyData['COUNTRYCODE'],0,6)][ $strategyData['COUNTRYCODE']];
					}elseif ($area_len==12){
						$strProvince = $Province2[substr( $strategyData['COUNTRYCODE'],0,6)].$City[substr( $strategyData['COUNTRYCODE'],0,6)][substr( $strategyData['COUNTRYCODE'],0,9)].$County[substr( $strategyData['COUNTRYCODE'],0,9)][ $strategyData['COUNTRYCODE']];
					}
					$strategyData['AREAINFO'] = $strProvince;
				}
			}
			//获取用户账号信息
			if($strategyData['USERID']){
				$userSql = "select id,username,userpwd,checkState,checker, checktime,dateline,firstTime from users where id = ".trim($strategyData['USERID'])." limit 1 ";
			    $arrUserData = DB::select($userSql);
				if($arrUserData){
					$crypt = new Crypt();//密码加密
			        $userpwd = $crypt->decode($arrUserData[0]['USERPWD']);
					$arrUserData[0]['PASSWORD'] = $userpwd;
					$arrUserData = $arrUserData[0];
					$this->assign('arrUserData',$arrUserData);
				}
			}



		}else{
			$this->goTo404('该信息不存在!');
		}

		$this->assign('strategyData',$strategyData);
//		print_r($strategyData);
		$this->assign('p',$p);
		$this->assign('menu_navbar','合作管理  -- <a href="'.$_GET['action'].'.html">战略合作列表</a> -- 战略合作详情');
		$this->tpl_full_path('/admins/strategy_manage/view');
	}
	
	
	/**
	**账号处理
	**/
	public function _accountdo(){
		if($_SERVER['REQUEST_METHOD']=='POST'){
			$adminid = $this->session()->getSession('ADMINID');
		    $strUserName = $this->getParam('uname');
			$strUserPass = $this->getParam('upass');
			$cid = $this->getParam('cid');
			
			if(empty($strUserName) || empty($strUserPass)){
				die('error');
			}
			
			#创建数据库操作对象
			$objUser = $this->getModel('users');
			#检查用户是否存在
			$mysqlData = $objUser->getUserInfo($strUserName);
			if(count($mysqlData) > 0){
				die('error_user');
			}
			
			$crypt = new Crypt();//密码加密
			$userPassword = $crypt->encode($strUserPass);
			
			#插入变量处理
			$inserData = array();
			$inserData['username'] = $strUserName;
			$inserData['userpwd'] = $userPassword;
			$inserData['checkState'] = 2;
			$inserData['checker'] = $adminid;
			$inserData['checktime'] =  time();
			$inserData['dateline'] = time();
			$inserData['firstTime'] = time();
 
			$doStatus = DB::insert('users',$inserData,true);
			
			if($doStatus){
				$updateData = array();
				$updateData['userId'] = $doStatus;
				$updateStatus = DB::update('sc_corpinfo','id = '.$cid,$updateData);
				die('ok');
			}else{
				die('error');
			}
			
			
		}
		
		die('error');
	}





}
?>
